package zjh_20230406;

import java.io.IOException;
import java.net.*;

public class UDPSender {

    public static void main(String[] args) {
        try {
            // ip
//            InetAddress localhost = InetAddress.getLocalHost();
            InetAddress localhost = InetAddress.getByName("10.0.3.198");
            int port = 8888;
            // 创建发送端
            String msg = "Hi Mrs.Ma";
            DatagramPacket packet = new DatagramPacket(msg.getBytes(), msg.getBytes().length, localhost, port);

            DatagramSocket datagramSocket = new DatagramSocket(8080, localhost);

            // 发送
            datagramSocket.send(packet);

        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        } catch (SocketException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
